package com.tiheima.arrlist;

import java.util.*;

public class Test {
    public static void main(String[] args) {
//        ArrayList有以下元素: "a","f","b","c","a","d"，请用任意方式完成集合元素去重。去除集合中重复的元素。
        ArrayList<String> list = new ArrayList<>();
        getList(list);
        //HashSet<String> set = new HashSet<>();
        list.stream().distinct().forEach(s-> System.out.println(s));
        TreeSet<String> set = new TreeSet<>();
        for (int i = 0; i < list.size(); i++) {
            set.add(list.get(i));
        }
        list.clear();
        for (String s : set) {
            list.add(s);
        }
        System.out.println(list);
    }

//    private static void delete(ArrayList<String> list) {
//        ArrayList<String> list2 = new ArrayList<>();
//        for (int i = 0; i < list.size(); i++) {
//            for (int j = 0; j < list.size(); j++) {
//                if(list.get(i).equals(list.get(j))){
//
//                    list.remove(j);
//
//                }
//            }
//        }
//        System.out.println(list);
//    }

    private static void getList(ArrayList<String> list) {
        String s = "a,f,b,c,a,d";
        String[] split = s.split(",");
        for (String s1 : split) {
            list.add(s1);
        }
    }
}
